package cz.muni.fi.pa165.musiclibrary.impl.service.dto.translator;

import org.apache.commons.lang3.Validate;

import cz.muni.fi.pa165.musiclibrary.impl.database.entity.IGenre;
import cz.muni.fi.pa165.musiclibrary.api.service.dto.IGenreDTO;
import cz.muni.fi.pa165.musiclibrary.impl.database.entity.Genre;
import cz.muni.fi.pa165.musiclibrary.impl.service.dto.GenreDTO;

/**
 * Class with static methods for translating between {@link IGenre} 
 * and {@link IGenreDTO} objects.
 * 
 * @author Maros Kucbel
 * @date 2012-10-28T15:37:50+0100
 */
public final class GenreDTOTranslator {

    /**
     * Translates {@link IGenre} object into {@link IGenreDTO} object.
     * @param genre Genre.
     * @return Instance of {@link IGenreDTO} that correspons with given parameter.
     */
    public static IGenreDTO translateToDTO(final IGenre genre) {
        if (genre == null) {
            return null;
        }
        final IGenreDTO genreDTO = new GenreDTO();
        genreDTO.setIdGenre(genre.getIdGenre());
        genreDTO.setName(genre.getName());
        return genreDTO;
    }
    
    /**
     * Translates {@link IGenreDTO} object into {@link IGenre} object.
     * @param genre GenreDTO.
     * @return Instance of {@link IGenre} that correspons with given parameter.
     * @throws IllegalArgumentException If parameter is {@code null}.
     */
    public static IGenre translateFromDTO(final IGenreDTO genreDTO) {
        Validate.isTrue(genreDTO != null, "GenreDTO should not be null.");
        final IGenre genre = new Genre();
        if(genreDTO.getIdGenre()!=null) {
            genre.setIdGenre(genreDTO.getIdGenre());
        }
        genre.setName(genreDTO.getName());
        return genre;
    }
}